package game;

import core.net.protocol.FrameCheckP;
import core.net.protocol.IProtocol;
import core.net.protocol.MoveP;
import core.net.protocol.Protocol;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiConsumer;

public class Scene {

    private String _name;
    public List<Player> _playerList = new ArrayList<>();
    public BiConsumer<IProtocol, Player> _handleCMD = this::handleCMD;

    private void handleCMD(IProtocol cmd, Player player) {
        System.out.println("[receive CMD] " + (cmd));
    }

    public void entry(Player player) {
        _playerList.add(player);

    }

    public void quit(Player player) {

    }

    long time;
    long use;
    long del = 1000;

    public void update() throws InterruptedException {

        time = System.currentTimeMillis();
        for (int i = 0; i < _playerList.size(); i++) {
            Player player = _playerList.get(i);
            while (player.cmds.size()>0) {
                _handleCMD.accept(player.cmds.dequeue(), player);
            }
        }
        use = System.currentTimeMillis() - time;
        Thread.sleep(del - use);
    }

}
